﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MINERP.DAL;
using MINERP.MODEL.FoundationModel;

namespace MINERP.BLL.InfoConfig
{
    public  class WorkShopBLL
    {
        public WorkShop_Info GetWorkShop()
        {
            WorkShop_Info workShopInfo = null;
            using (newSampleYPDBEntities enty = new newSampleYPDBEntities())
            {
                WorkShop workShop = enty.WorkShop.FirstOrDefault();
                workShopInfo = new WorkShop_Info()
                {
                    Address = workShop.Address,
                    CustomerTel = workShop.CustomerTel,
                    Email = workShop.Email,
                    FinanceTel = workShop.FinanceTel,
                    QQ = workShop.QQ,
                    WorkShopId = workShop.WorkShopId,
                    Remark = workShop.Remark,
                    WorkShopName = workShop.WorkShopName,
                    AutoAssignShop = workShop.AutoAssignShop,
                    ControlNonexistenceTechByPriority = workShop.ControlNonexistenceTechByPriority,
                    InsertEPByPhotoSpec = workShop.InsertEmployeePerfermanceByPhotoSpec


                };
                
            }

            return workShopInfo;
        }

        public void Update(WorkShop_Info workShopInfo)
        {
            try
            {
                using (newSampleYPDBEntities enty = new newSampleYPDBEntities())
                {
                    WorkShop workShop = enty.WorkShop.FirstOrDefault();
                    if (workShop != null)
                    {
                        workShop.Address = workShopInfo.Address;
                        workShop.CustomerTel = workShopInfo.CustomerTel;
                        workShop.Email = workShopInfo.Email;
                        workShop.FinanceTel = workShopInfo.FinanceTel;
                        workShop.QQ = workShopInfo.QQ;
                        workShop.Remark = workShopInfo.Remark;
                        workShop.WorkShopName = workShopInfo.WorkShopName;
                        workShop.AutoAssignShop = workShopInfo.AutoAssignShop;
                        workShop.InsertEmployeePerfermanceByPhotoSpec = workShopInfo.InsertEPByPhotoSpec;
                        workShop.ControlNonexistenceTechByPriority = workShopInfo.ControlNonexistenceTechByPriority;
                    }
                    else
                    {
                        workShop = new WorkShop();
                        workShop.Address = workShopInfo.Address;
                        workShop.CustomerTel = workShopInfo.CustomerTel;
                        workShop.Email = workShopInfo.Email;
                        workShop.FinanceTel = workShopInfo.FinanceTel;
                        workShop.QQ = workShopInfo.QQ;
                        workShop.Remark = workShopInfo.Remark;
                        workShop.WorkShopName = workShopInfo.WorkShopName;
                        workShop.AutoAssignShop = workShopInfo.AutoAssignShop;
                        workShop.InsertEmployeePerfermanceByPhotoSpec = workShopInfo.InsertEPByPhotoSpec;
                        workShop.ControlNonexistenceTechByPriority = workShopInfo.ControlNonexistenceTechByPriority;
                        enty.AddToWorkShop(workShop);

                    }
                    enty.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
